package com.gao.io;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class CharactorTest {
    /*
        统计文件中每一个字符出现的次数
        记得关流操作啊~~~~
     */
    public static void main(String[] args) throws IOException {
        FileReader reader = new FileReader("E://A.text");
        Map<Character,Integer> map = new HashMap<>();
        int i;
        while((i=reader.read())!=-1){
            char charator = (char) i;
            if(!map.containsKey(charator)){
                map.put(charator,1);
            }else{
                map.put(charator,map.get(charator)+1);
            }
        }
        reader.close();
        StringBuilder stringBuilder = new StringBuilder();
        map.forEach(new BiConsumer<Character, Integer>() {
            @Override
            public void accept(Character character, Integer integer) {
                stringBuilder.append(character).append("(").append(integer).append(")");
            }
        });
        System.out.println(stringBuilder);
    }
}
